package com.lmk.qs.jdbc;

import com.lmk.qs.domain.Map;
import com.lmk.qs.utils.DruidUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class text09 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DruidUtil.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from emp");
        ResultSetMetaData data = rs.getMetaData();

        ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String, String>>();

        while (rs.next()) {
            HashMap<String, String> map = new HashMap<String, String>();
            for (int i = 1; i <= data.getColumnCount(); i++) {// 数据库里从 1 开始

                String c = data.getColumnName(i);
                String v = rs.getString(c);
                System.out.println(c + ":" + v + "\t");
                map.put(c, v);
            }
            System.out.println("======================");
            al.add(map);
        }
        System.out.println(al);
        rs.close();
        stmt.close();
        conn.close();
    }
}
